<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="88px"
    >
      <el-form-item label="玻璃ID" prop="glassId">
        <el-input
          v-model="queryParams.glassId"
          placeholder="请输入玻璃ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工作单ID" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入工作单ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原片宽度" prop="originalWidth">
        <el-input
          v-model="queryParams.originalWidth"
          placeholder="请输入原片宽度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原片高度" prop="originalHeight">
        <el-input
          v-model="queryParams.originalHeight"
          placeholder="请输入原片高度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原片数量" prop="originalNum">
        <el-input
          v-model="queryParams.originalNum"
          placeholder="请输入原片数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="切割前宽度" prop="cutWidth">
        <el-input
          v-model="queryParams.cutWidth"
          placeholder="请输入切割前宽度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="切割前高度" prop="cutHeight">
        <el-input
          v-model="queryParams.cutHeight"
          placeholder="请输入切割前高度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="切割X轴" prop="cutX">
        <el-input
          v-model="queryParams.cutX"
          placeholder="请输入切割X轴"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="切割Y轴" prop="cutY">
        <el-input
          v-model="queryParams.cutY"
          placeholder="请输入切割Y轴"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单宽度" prop="orderWidth">
        <el-input
          v-model="queryParams.orderWidth"
          placeholder="请输入订单宽度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单高度" prop="orderHeight">
        <el-input
          v-model="queryParams.orderHeight"
          placeholder="请输入订单高度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="玻璃厚度" prop="thick">
        <el-input
          v-model="queryParams.thick"
          placeholder="请输入玻璃厚度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientName">
        <el-input
          v-model="queryParams.clientName"
          placeholder="请输入客户名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="条码号" prop="barcode">
        <el-input
          v-model="queryParams.barcode"
          placeholder="请输入条码号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="版号" prop="plate">
        <el-input
          v-model="queryParams.plate"
          placeholder="请输入版号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="干扰码" prop="disturbCode">
        <el-input
          v-model="queryParams.disturbCode"
          placeholder="请输入干扰码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="线号" prop="lineIndex">
        <el-input
          v-model="queryParams.lineIndex"
          placeholder="请输入线号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="玻璃下架号" prop="downFrameMark">
        <el-input
          v-model="queryParams.downFrameMark"
          placeholder="请输入玻璃下架号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dll:glass:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dll:glass:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dll:glass:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dll:glass:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="glassList">
      <el-table-column label="OPT玻璃ID" align="center" prop="id" width="120" />
      <el-table-column label="玻璃ID" align="center" prop="glassId" width="120" />
      <el-table-column label="工作单ID" align="center" prop="orderId" width="120" />
      <el-table-column label="原片宽度" align="center" prop="originalWidth" width="120" />
      <el-table-column label="原片高度" align="center" prop="originalHeight" width="120" />
      <el-table-column label="原片数量" align="center" prop="originalNum" width="120" />
      <el-table-column label="切割前宽度" align="center" prop="cutWidth" width="120" />
      <el-table-column label="切割前高度" align="center" prop="cutHeight" width="120" />
      <el-table-column label="切割X轴" align="center" prop="cutX" width="120" />
      <el-table-column label="切割Y轴" align="center" prop="cutY" width="120" />
      <el-table-column label="订单宽度" align="center" prop="orderWidth" width="120" />
      <el-table-column label="订单高度" align="center" prop="orderHeight" width="120" />
      <el-table-column label="玻璃厚度" align="center" prop="thick" width="120" />
      <el-table-column label="玻璃类型" align="center" prop="type" width="120" />
      <el-table-column label="客户名称" align="center" prop="clientName" width="120" />
      <el-table-column label="条码号" align="center" prop="barcode" width="120" />
      <el-table-column label="版号" align="center" prop="plate" width="120" />
      <el-table-column label="干扰码" align="center" prop="disturbCode" width="120" />
      <el-table-column
        label="线号"
        align="center"
        prop="lineIndex"
      />
      <el-table-column label="玻璃下架号" align="center" prop="downFrameMark" width="150" />
      <el-table-column
        label="操作"
        align="center"
        fixed="right"
        width="150"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改解析OPT所有信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-form-item label="玻璃ID" prop="glassId">
          <el-input v-model="form.glassId" placeholder="请输入玻璃ID" />
        </el-form-item>
        <el-form-item label="工作单ID" prop="orderId">
          <el-input v-model="form.orderId" placeholder="请输入工作单ID" />
        </el-form-item>
        <el-form-item label="原片宽度" prop="originalWidth">
          <el-input v-model="form.originalWidth" placeholder="请输入原片宽度" />
        </el-form-item>
        <el-form-item label="原片高度" prop="originalHeight">
          <el-input
            v-model="form.originalHeight"
            placeholder="请输入原片高度"
          />
        </el-form-item>
        <el-form-item label="原片数量" prop="originalNum">
          <el-input v-model="form.originalNum" placeholder="请输入原片数量" />
        </el-form-item>
        <el-form-item label="切割前宽度" prop="cutWidth">
          <el-input v-model="form.cutWidth" placeholder="请输入切割前宽度" />
        </el-form-item>
        <el-form-item label="切割前高度" prop="cutHeight">
          <el-input v-model="form.cutHeight" placeholder="请输入切割前高度" />
        </el-form-item>
        <el-form-item label="切割X轴" prop="cutX">
          <el-input v-model="form.cutX" placeholder="请输入切割X轴" />
        </el-form-item>
        <el-form-item label="切割Y轴" prop="cutY">
          <el-input v-model="form.cutY" placeholder="请输入切割Y轴" />
        </el-form-item>
        <el-form-item label="订单宽度" prop="orderWidth">
          <el-input v-model="form.orderWidth" placeholder="请输入订单宽度" />
        </el-form-item>
        <el-form-item label="订单高度" prop="orderHeight">
          <el-input v-model="form.orderHeight" placeholder="请输入订单高度" />
        </el-form-item>
        <el-form-item label="玻璃厚度" prop="thick">
          <el-input v-model="form.thick" placeholder="请输入玻璃厚度" />
        </el-form-item>
        <el-form-item label="客户名称" prop="clientName">
          <el-input v-model="form.clientName" placeholder="请输入客户名称" />
        </el-form-item>
        <el-form-item label="条码号" prop="barcode">
          <el-input v-model="form.barcode" placeholder="请输入条码号" />
        </el-form-item>
        <el-form-item label="版号" prop="plate">
          <el-input v-model="form.plate" placeholder="请输入版号" />
        </el-form-item>
        <el-form-item label="干扰码" prop="disturbCode">
          <el-input v-model="form.disturbCode" placeholder="请输入干扰码" />
        </el-form-item>
        <el-form-item label="线号(0 精磨 1 粗磨)" prop="lineIndex">
          <el-input
            v-model="form.lineIndex"
            placeholder="请输入线号(0 精磨 1 粗磨)"
          />
        </el-form-item>
        <el-form-item label="玻璃下架号" prop="downFrameMark">
          <el-input
            v-model="form.downFrameMark"
            placeholder="请输入玻璃下架号"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listGlass2,
  getGlass,
  delGlass,
  addGlass,
  updateGlass,
} from "@/api/assembly/glass";

export default {
  name: "Glass",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 解析OPT所有信息表格数据
      glassList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        glassId: null,
        orderId: null,
        originalWidth: null,
        originalHeight: null,
        originalNum: null,
        cutWidth: null,
        cutHeight: null,
        cutX: null,
        cutY: null,
        orderWidth: null,
        orderHeight: null,
        thick: null,
        type: null,
        clientName: null,
        barcode: null,
        plate: null,
        disturbCode: null,
        lineIndex: null,
        downFrameMark: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderId: [
          { required: true, message: "工作单ID不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询解析OPT所有信息列表 */
    getList() {
      this.loading = true;
      listGlass2(this.queryParams).then((response) => {
        this.glassList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        glassId: null,
        orderId: null,
        originalWidth: null,
        originalHeight: null,
        originalNum: null,
        cutWidth: null,
        cutHeight: null,
        cutX: null,
        cutY: null,
        orderWidth: null,
        orderHeight: null,
        thick: null,
        type: null,
        clientName: null,
        barcode: null,
        plate: null,
        disturbCode: null,
        lineIndex: null,
        downFrameMark: null,
        createBy: null,
        createTime: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加解析OPT所有信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getGlass(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改解析OPT所有信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateGlass(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addGlass(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除解析OPT所有信息编号为"' + ids + '"的数据项？')
        .then(function () {
          return delGlass(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "dll/glass/export",
        {
          ...this.queryParams,
        },
        `glass_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
